<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title>37练习：折叠菜单</title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            .nav{
                list-style: none;
                width:300px;
                margin: 100px auto;
                /* border: 1px solid #000; */
            }
            .nav>li{
                border: 1px solid #000;
                line-height: 35px;
                border-bottom: none;
                text-indent: 2em;
            }
            .nav>li:last-child{
                border-bottom: 1px solid #000;
                border-bottom-right-radius: 10px;
                border-bottom-left-radius: 10px;
            }
            .nav>li:first-child{
                border-top-right-radius: 10px;
                border-top-left-radius: 10px;
            }
            .nav>li>span{
                background: url(img/nezha.jpg) no-repeat center center;
                display: inline-block;
                width: 32px;
                height: 32px;
                position: absolute;
                right: 10px;
                top: 5px;
            }
            .sub{
                display: none;
            }
            .sub>li{
                list-style: none;
                background: mediumslateblue;
                border-bottom: 1px solid rgb(243, 241, 241);
            }
            .sub>li:hover{
                background: red;
            }
            .nav>.current>span{
                transform: rotate(90deg);
            }
        </style>
        <script src="http://code.jquery.com/jquery-1.12.4.js" 
        integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU="
        crossorigin="anonymous"></script>
        <script>
            $(function (param) {  
                //1.监听一级菜单的点击事件
                $(".nav>li").click(function (param) { 
                    //1.1拿到二级菜单
                    var $sub=$(this).children(".sub");
                    //1.2让二级菜单展开
                    $sub.slideDown(1000);
                    //1.3拿到所有非当前的菜单
                    var otherSub=$(this).siblings().children(".sub");
                    //1.4让所有非当前的二级菜单收起
                    otherSub.slideUp(1000);
                    //1.5让被点击的一级菜单箭头旋转
                    $(this).addClass(".current");
                    //1.6让所有非被点击的一级菜单还原
                    $(this).siblings().removeClass("current");
                 });

            });
        </script>
    </head>
    <body>
        <ul class="nav">
            <li class="current">一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
            <li>一级菜单<span></span>
                <ul class="sub">
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                    <li>二级菜单</li>
                </ul>
            </li>
        </ul>
    </body>
</html>